<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        body {
            margin: 0px;
            padding: 0px;
        }
        
        * {
            box-sizing: content-box;
        }
        
        #staff {
            position: relative;
            width: 1120px;
            margin: 0px auto;
        }
        
        #lines .lines:nth-child(2n) {
            background: #f5f5f5
        }
        
        #lines .lines {
            height: 256px;
        }
        
        .line {
            border-bottom: 1px solid black;
            height: 15px;
        }
        
        .line.noline {
            border-bottom-color: transparent;
        }
        
        #notes {
            position: absolute;
            top: 0px;
            left: 0px;
            right: 0px;
        }
        
        .note {
            width: 4%;
            float: left;
            height: 256px;
            position: relative;
        }
        
        .point {
            position: absolute;
            width: 100%;
            height: 16px;
        }
        
        .point::before {
            border-radius: 50px;
            content: "";
            border: 8px solid black;
            width: 0px;
            height: 0px;
            position: absolute;
            left: 50%;
            transform: translateX(-50%);
        }
        
        .point.red::before {
            border-color: red;
        }
        
        .point.nopoint::before {
            border-color: transparent;
        }
        
        .point.bottom::after {
            content: "";
            border-bottom: 1px solid black;
            position: absolute;
            width: 100%;
            top: 100%;
        }
        
        .point.middle::after {
            content: "";
            border-bottom: 1px solid black;
            position: absolute;
            width: 100%;
            top: 50%;
        }
        
        .point.top::after {
            content: "";
            border-top: 1px solid black;
            position: absolute;
            width: 100%;
        }
    </style>
</head>

<body>
    <div id="staff">
        <div id="lines">
        </div>
        <div id="notes">
        </div>
        <div>
            <div>题目：当前是第<span id="qn"></span>题</div>
            <div>
                <input type="text" id="an" onkeydown="enter()">
                <button onclick="valid()">提交</button>
            </div>
            <div>答案：</div>
            <div id="right">

            </div>
        </div>
    </div>
    <div id="aaa"></div>
    <div id="bbb"></div>
</body>
<script>
    document.addEventListener
    let notes = [];
    let questionIndex = 0;

    function gentateLine(num = 1) {
        for (let n = 0; n < num; n++) {
            let parent = document.createElement("div");
            parent.className = "lines";
            let doms = document.createDocumentFragment();
            for (let i = 0; i < 5; i++) {
                let div = document.createElement("div");
                div.className = "line noline";
                doms.appendChild(div);
            }
            for (let i = 0; i < 5; i++) {
                let div = document.createElement("div");
                div.className = "line";
                doms.appendChild(div);
            }
            for (let i = 0; i < 5; i++) {
                let div = document.createElement("div");
                div.className = "line noline";
                doms.appendChild(div);
            }
            parent.appendChild(doms);
            document.getElementById("lines").appendChild(parent);
        }
    }
    // gentateLine();

    function gentateNote() {
        let staffs = 100;
        let dom = document.createDocumentFragment();
        for (let i = 0; i < staffs; i++) {
            let note = (Math.random() * 31 / 10).toFixed(1) * 10;
            note = note < 1 ? 1 : note;
            // note = 17
            notes.push(note);
            // note = 27;
            let div = document.createElement("div");
            div.className = "note";
            let childDiv = document.createElement("div");
            childDiv.className = "point";

            // if (note > 2 && note < 12) {
            childDiv.style.top = (240 - (note - 1) * 8) - 1 + "px";

            if (note < 11) {
                let tempLinesLen = Math.floor((10 - note) / 2);
                for (let j = 0; j < tempLinesLen; j++) {
                    let tempDiv = document.createElement("div");
                    tempDiv.className = "point nopoint top";
                    tempDiv.style.top = 256 - (Math.ceil(note / 2) + 1 + j) * 16 - 1 + "px";
                    div.appendChild(tempDiv);
                }

                if (note % 2 == 0) {
                    childDiv.classList.add("middle")
                } else {
                    childDiv.classList.add("top")
                }
            } else if (note > 21) {
                let tempLinesLen = Math.floor((note - 21) / 2);
                for (let j = 0; j < tempLinesLen; j++) {
                    let tempDiv = document.createElement("div");
                    tempDiv.className = "point nopoint bottom";
                    tempDiv.style.top = 256 - (Math.ceil(note / 2) - j) * 16 - 1 + "px";
                    div.appendChild(tempDiv);
                }
                if (note % 2 == 0) {
                    childDiv.classList.add("middle")
                } else {
                    childDiv.classList.add("bottom")
                }
            }
            div.appendChild(childDiv);
            // }
            dom.appendChild(div);
            // notes.push(note);
            // document.getElementById("aaa").innerText += note / countlinenum + "," + note + "," + countlinenum
            // document.getElementById("aaa").innerText += note + ','
        }
        document.getElementById("notes").appendChild(dom);
        gentateLine(Math.floor(staffs / 25) < 1 ? 1 : Math.floor(staffs / 25));
    }

    function init() {
        questionIndex = 0;
        gentateNote();
        gentalQuestion();
    }
    init();

    function gentalQuestion() {
        document.getElementById("qn").innerText = questionIndex + 1;
        document.getElementById("an").value = "";
        for (let i = 0; i < notes.length; i++) {
            if (i == questionIndex) {
                document.getElementById("notes").childNodes[i + 1].lastChild.classList.add("red");
            } else {
                document.getElementById("notes").childNodes[i + 1].lastChild.classList.remove("red");
            }
        }
    }

    function enter() {
        if (event.keyCode == 13) {
            valid();
        }
    }

    function valid() {
        let an = document.getElementById("an").value;
        let right = convent10to7(notes[questionIndex] - 2);
        if (an == right) {
            document.getElementById("right").innerText += document.getElementById("an").value + ',';
        } else {
            document.getElementById("right").innerHTML += "<span style='color:red'>" + document.getElementById("an").value + '</span>,';
        }
        // document.getElementById("aaa").innerText += convent10to7(notes[questionIndex] - 2) + ','
        questionIndex++;
        gentalQuestion();
    }

    function convent10to7(value) {
        let num = 0;
        if (value < 1) {
            value = value + 7;
        }
        let source = Math.floor(value / 7);
        num = value - 7 * source;
        num = num == 0 ? 7 : num;
        return num;


        calc(value);
        return parseInt(num);

        function calc(source) {
            if (source < 1) {
                source = source + 7;
            }
            if (source > 7) {
                source = source / 7;
                calc(Math.ceil(source));
            } else {
                num = source;
                return;
            }
        }
    }
</script>

</html>